package com.hdd.utils.wxUtils;


import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * 返回给页面或者app端的响应对象
 */
@Setter
@Getter
@ToString
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**** 是否成功 ****/
    private Boolean success;

    /**** 返回码 ****/
    private int code;

    /**** 描述信息 ****/
    private String msg;

    /**** 数据 ****/
    private T data;

    /** 总记录数(条数) */
    private Integer totalCount;

    /**** 其他数据 ****/
    private Object extData;

    public Result() {
        this.success = true;
        this.msg="成功";
        this.code=0;
    }

    public Result(boolean success) {
        this.success = success;
        if (!success) {
            this.code = -1;
            this.msg="失败";
        }
    }

    public Result(boolean success, String msg) {
        this(success);
        this.msg = msg;
    }

    public Result(boolean success, int code, String msg) {
        this(success, msg);
        this.code = code;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public Result(T data) {
        this();
        this.data = data;
//        // 如果data是Page对象，说明是分页查询
//        if (data instanceof PageTableResponse) {
//            PageTableResponse page = (PageTableResponse) data;
//            this.totalCount = page.getRecordsTotal();
//            this.data = (T) page.getData();
//        }
    }

}
